﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Portal.Core;
using bUser = Portal.Core.Customer.bUser;

public partial class Controls_Login : System.Web.UI.UserControl
{
    string username = string.Empty;
    string password = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_login_Click(object sender, EventArgs e)
    {
        username = txbuser.Text.Trim();
        password = MD5.EncPwd(txbpass.Text.Trim());
        int UserID = bUser.CheckLoginUserWeb(username, password);
        if (UserID > 0)
        {
            if (set_cookie.Checked)
            {
                Response.Cookies["username"].Value = username;
                Response.Cookies["password"].Value = password;
            }
            Session.Contents.Add("UserID", UserID.ToString());
            Session.Contents.Add("username", username);
            Response.Redirect(Informations.basepath + "Default.aspx");
        }
        else
        {
            string str = "<script language='javascript' type='text/javascript'>";
            str += "alert('Tài khoản đăng nhập không đúng hoặc chưa kích hoạt, mời nhập lại!');</script>";
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "canhbao", str);
            string str1 = "<script language='javascript' type='text/javascript'>";
            str1 += "jQuery(function () { Popup.showModal('divLogin');});</script>";
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ButtonClickScript", str1);
        }
    }
}